package de.jmda.gui.swing;

import java.awt.Frame;

import java.util.logging.Level;
import java.util.logging.Logger;

import javax.naming.InitialContext;
import javax.naming.NamingException;

import javax.swing.JDialog;

/**
 *
 */
public class DialogLogin extends JDialog
{
  public enum ExitCode
  {
    LOGIN,
    CANCEL,
    FORGOT,
    REGISTER
  }

  private ExitCode exitCode = ExitCode.CANCEL;

  public ExitCode getExitCode()
  {
    return exitCode;
  }

    /** Creates new form DialogLogin */
    public DialogLogin(Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {
    java.awt.GridBagConstraints gridBagConstraints;

    jPanelUserCredentials = new javax.swing.JPanel();
    jLabelUsername = new javax.swing.JLabel();
    jLabelPassword = new javax.swing.JLabel();
    jTextFieldUsername = new javax.swing.JTextField();
    jPasswordField = new javax.swing.JPasswordField();
    jPanelLoginCancel = new javax.swing.JPanel();
    jButtonLogin = new javax.swing.JButton();
    jButtonCancel = new javax.swing.JButton();
    jButtonForgotUsernamePassword = new javax.swing.JButton();
    jButtonRegister = new javax.swing.JButton();

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    setMinimumSize(new java.awt.Dimension(200, 150));
    getContentPane().setLayout(new java.awt.GridBagLayout());

    jPanelUserCredentials.setLayout(new java.awt.GridBagLayout());

    jLabelUsername.setText("username");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    jPanelUserCredentials.add(jLabelUsername, gridBagConstraints);

    jLabelPassword.setText("password");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 1;
    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    jPanelUserCredentials.add(jLabelPassword, gridBagConstraints);
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    gridBagConstraints.weightx = 1.0;
    jPanelUserCredentials.add(jTextFieldUsername, gridBagConstraints);
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 1;
    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    gridBagConstraints.weightx = 1.0;
    jPanelUserCredentials.add(jPasswordField, gridBagConstraints);

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    gridBagConstraints.weightx = 1.0;
    getContentPane().add(jPanelUserCredentials, gridBagConstraints);

    jPanelLoginCancel.setLayout(new java.awt.GridBagLayout());

    jButtonLogin.setText("login");
    jButtonLogin.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButtonLoginActionPerformed(evt);
      }
    });
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 2;
    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    gridBagConstraints.weightx = 1.0;
    jPanelLoginCancel.add(jButtonLogin, gridBagConstraints);

    jButtonCancel.setText("cancel");
    jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButtonCancelActionPerformed(evt);
      }
    });
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 2;
    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    gridBagConstraints.weightx = 1.0;
    jPanelLoginCancel.add(jButtonCancel, gridBagConstraints);

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 2;
    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    gridBagConstraints.weightx = 1.0;
    gridBagConstraints.insets = new java.awt.Insets(2, 0, 0, 0);
    getContentPane().add(jPanelLoginCancel, gridBagConstraints);

    jButtonForgotUsernamePassword.setText("forgot username / password");
    jButtonForgotUsernamePassword.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButtonForgotUsernamePasswordActionPerformed(evt);
      }
    });
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 3;
    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    gridBagConstraints.insets = new java.awt.Insets(2, 0, 0, 0);
    getContentPane().add(jButtonForgotUsernamePassword, gridBagConstraints);

    jButtonRegister.setText("register");
    jButtonRegister.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButtonRegisterActionPerformed(evt);
      }
    });
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 4;
    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    gridBagConstraints.weightx = 1.0;
    gridBagConstraints.insets = new java.awt.Insets(2, 0, 0, 0);
    getContentPane().add(jButtonRegister, gridBagConstraints);

    pack();
  }// </editor-fold>//GEN-END:initComponents

    private void jButtonLoginActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonLoginActionPerformed
    {//GEN-HEADEREND:event_jButtonLoginActionPerformed
      exitCode = ExitCode.LOGIN;
    }//GEN-LAST:event_jButtonLoginActionPerformed

    private void jButtonCancelActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonCancelActionPerformed
    {//GEN-HEADEREND:event_jButtonCancelActionPerformed
      exitCode = ExitCode.CANCEL;
    }//GEN-LAST:event_jButtonCancelActionPerformed

    private void jButtonForgotUsernamePasswordActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonForgotUsernamePasswordActionPerformed
    {//GEN-HEADEREND:event_jButtonForgotUsernamePasswordActionPerformed
      exitCode = ExitCode.FORGOT;
    }//GEN-LAST:event_jButtonForgotUsernamePasswordActionPerformed

    private void jButtonRegisterActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonRegisterActionPerformed
    {//GEN-HEADEREND:event_jButtonRegisterActionPerformed
      exitCode = ExitCode.REGISTER;
    }//GEN-LAST:event_jButtonRegisterActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
//        EventQueue.invokeLater(new Runnable() {
//            public void run() {
//                DialogLogin dialog = new DialogLogin(new JFrame(), true);
//                dialog.addWindowListener(new WindowAdapter() {
//                    public void windowClosing(WindowEvent e) {
//                        System.exit(0);
//                    }
//                });
//                dialog.setVisible(true);
//            }
//        });
    }

  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JButton jButtonCancel;
  private javax.swing.JButton jButtonForgotUsernamePassword;
  private javax.swing.JButton jButtonLogin;
  private javax.swing.JButton jButtonRegister;
  private javax.swing.JLabel jLabelPassword;
  private javax.swing.JLabel jLabelUsername;
  private javax.swing.JPanel jPanelLoginCancel;
  private javax.swing.JPanel jPanelUserCredentials;
  private javax.swing.JPasswordField jPasswordField;
  private javax.swing.JTextField jTextFieldUsername;
  // End of variables declaration//GEN-END:variables
}